<?php
class DelegatorGiro extends DelegatorPrueba
{
	public function __construct() {}
	public function menorCarga(EFacade & $facade,$transSet) 
	{	
		
		//$this->porDepartamento($facade,$transSet);	
	}
	
	public function proceso(EFacade & $facade,$transSet) 
	{	
		
		$this->porDepartamento($facade,$transSet);		
	}
	
		public function porTurno(EFacade & $facade,$transSet) 
	{	
		$ezpdo_ = & getManager();
		$queryDep='FROM MDepartamento as t WHERE t.identificadorUnico=?';
		$doc = & $facade->getDocumentRoot();
		$usuarioActual=$doc->usuarioActual;
		$idDep=$doc->departamento->identificadorUnico;
		$variante=$doc->variante;
		$workflow= & $facade->getWorkflow();
		$areaTrabajo=NULL;
		$role=NULL;
		$cont=0;
	    $currentTransSet=$facade->getCurrentTransSet($workflow,$role);
		$currentPlaceSet=$facade->getCurrentPlaceSet($workflow);
		$dptoVarietyList=$currentPlaceSet->dptoVarietyList;
		foreach($dptoVarietyList as $dv){
			
			foreach($dv->variantList as $v){
				if($v->epGetObjectId()==$variante->epGetObjectId()){
					
					
					$departamento1=$ezpdo_->find($queryDep,$dv->dptoName);
					$doc->departamento=$departamento1[0];
					$doc->variante=$v;
				}
			}
			
		}
		$role=$currentTransSet->transList[0]->roleRef;
		//echo '<br>departamento',$doc->departamento;
		
		$query = 'FROM MUser as u WHERE u.perfilList.contains(p) AND p.roleList.contains(?) AND u.empleado.departamento=?';
			$users = $ezpdo_->find($query, $role,$doc->departamento);
		
			
		//$users = $session->find($query, $role,$areaTrabajo);
		$ret=NULL;
		foreach ($users as & $user) {
			if ($ret == null) {
				$ret = & $user;
			}

			if ($user->getActorList()->count() < $ret->getActorList()->count()) {
				$ret = & $user;
			}
		}
		
		$workTransList= & $workflow->workTransList;
		$transList=$currentTransSet->transList;
		foreach($workTransList as $wt){
			
			foreach($transList as $t){
				
				if($wt->transRef->epGetObjectId()==$t->epGetObjectId()){
					
					$wt->actorRef->userRef=$ret;
				}
			}
		}
		
		
	}
}
?>